package jay.docghi;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class DocGhiFlieActivity extends Activity {
    /** Called when the activity is first created. */
	SharedPreferences setting;
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setting = getSharedPreferences("xxx_11", 0);
    }
    public void savefile(View v){
    	//RadioGroup gr1=(RadioGroup) findViewById(R.id.rg);
    	
    	RadioButton b11=(RadioButton) findViewById(R.id.b1);
    	RadioButton b12=(RadioButton) findViewById(R.id.b2);
    	RadioButton b13=(RadioButton) findViewById(R.id.b3);
    	int kq=-1;
    	if(b11.isChecked()==true)
    	{
    		kq=1;
    	}
    	else if(b12.isChecked()==true)
    	{
    		kq=2;
    	}
    	else if(b13.isChecked()==true)
    	{
    		kq=3;
    	}

    	EditText t1=(EditText) findViewById(R.id.t11);
    	String tsb=t1.getText().toString();
    	EditText t2=(EditText) findViewById(R.id.t12);
    	String tt=t2.getText().toString();
    	SharedPreferences.Editor editor = setting.edit();
    	editor.putString("t111", tsb);
    	editor.putString("t222", tt);
    	editor.putInt("t333", kq );
 
    	
    	Toast.makeText(this, "Bạn nhập thành công !", Toast.LENGTH_LONG).show();
    	editor.commit();
    	
    }
    
    public void loadfile(View v)
    {
    	EditText tv1=(EditText) findViewById(R.id.t1);
    	EditText tv2=(EditText) findViewById(R.id.t2);
    	EditText tv3=(EditText) findViewById(R.id.t3);
    	String tv11=setting.getString("t111", "");
    	String tv12=setting.getString("t222", "");
    	RadioButton b11=(RadioButton) findViewById(R.id.b1);
    	RadioButton b12=(RadioButton) findViewById(R.id.b2);
    	RadioButton b13=(RadioButton) findViewById(R.id.b3);
    	tv2.setText(tv11);
    	tv3.setText(tv12 + ".txt");
    	int kq=setting.getInt("t333", -1);
    	if(kq==1)
    	{
    		b11.setChecked(true);
    	}
    	if(kq==2)
    	{
    		b12.setChecked(true);
    	}
    	if(kq==3)
    	{
    		b13.setChecked(true);
    	}
    	tv1.setText(""+kq);
    	Toast.makeText(this, "Load thanh cong " + kq, Toast.LENGTH_LONG).show();
    }
}